// 声明全局变量
declare const QWebChannel: any
declare const qt: any

// 初始化 pyqtapi 变量
let pyqtapi: any

/** 函数用于初始化 QWebChannel 并设置 pyqtapi */
function initializePyQtAPI() {
  if (typeof QWebChannel !== 'undefined' && typeof qt !== 'undefined') {
    new QWebChannel(qt.webChannelTransport, (channel: any) => {
      pyqtapi = channel.objects.windowController
    })
  } else {
    console.error('QWebChannel or qt is not available.')
  }
}

// 导出 pyqtapi 和初始化函数
export { pyqtapi, initializePyQtAPI }
